<?php
	require_once("user_session.php");
	if(isset($_GET['id'])){
		$id = $_GET['id'];
		$userId = $_SESSION["userid"];
		$authorId = EKParagraph::getElementValueById($id, "EKParagraph", "authorId");
		$ownerId = EKParagraph::getElementValueById($id, "EKParagraph", "ownerId");
		if ($userId == $authorId
		&& EKParagraph::getElementAttributeById($id, "EKParagraph", "status") == "pending"){
			
			$message = EKParagraph::deleteParagraphNode($id);
			
			echo "<script language=javascript>\n".
			        "alert(\"".$message[1]."\");\n";
			if($message[0]=="normal")
			{
				# means delete paragraph
				echo "self.location=\"document.php?id=".$ownerId."&method=v\";\n";
			}else{
				# means delete document
				echo "self.location=\"document.php?id=".$message[0]."&method=v\";\n";
			}
			echo "</script>";
		} else {
			echo "<script language=javascript>\n".
			        "alert(\"Either the paragraph is not in pending status or you are not the creator of paragraph Id: ". $id .".\");\n".
			        "history.go(-1);\n".
			        "</script>";
		}
	} else {
		echo "<script language=javascript>\n".
			        "history.go(-1);\n".
			        "</script>";
	}
?>